|
|
On Tue, 13 Nov 2001 23:16:02 -0500, "Redbeard" <red### [at] wvadelphianet> wrote:
> Hmmm... is this always guaranteed to work?
of course not
just check this with
#declare A = plane { x, 1 }
#declare B = plane { -x, 0 }
I can propose rather such macros (below). It is not tested hardly but seems
work. It could be extended with another level - sampled value for random points
(in bound) of function{pattern{object{I}}}.
I wonder what should be result for plane{x,1} and plane{x,0} ?
Your and mine returns "no intersection", but is it true ?
// A - first object
// B - second object
// S - sampling level
#macro Colision_Detection(A,B,S)
#local I=intersection{object{A}object{B}};
#declare Min=min_extent(I);
#declare Max=max_extent(I);
#local K=0;
#local Found=Sample_Detection(
<Min.x-.1,Min.y,Min.z>,
<Min.x-.1,Max.y,Min.z>,
<Min.x-.1,Max.y,Max.z>,
<Min.x-.1,Min.y,Max.z>,
x,S-1);
#if(!Found)
#local Found=Sample_Detection(
<Min.x,Min.y-.1,Min.z>,
<Max.x,Min.y-.1,Min.z>,
<Max.x,Min.y-.1,Max.z>,
<Min.x,Min.y-.1,Max.z>,
y,S-1);
#end
#if(!Found)
#local Found=Sample_Detection(
<Min.x,Min.y,Min.z-.1>,
<Min.x,Max.y,Min.z-.1>,
<Max.x,Max.y,Min.z-.1>,
<Max.x,Min.y,Min.z-.1>,
z,S-1);
#end
#debug concat("Sampling called ",str(K,0,0)," times\n")
(Found?true:false)
#end
// check ray sended from center of quad <P1,P2,P3,P4> in direction D
// if level S>0 then send subsample
#macro Sample_Detection(P1,P2,P3,P4,D,S)
#local N=y;
#local C=(P1-P3)/2;
#local T=trace(I,C,D,N);
#if(!(N.x=0 & N.y=0 & N.z=0))
#local Found=true;
#else
#if(S<0)
#local Found=false;
#else
#local Found=Sample_Detection(P1,(P1+P2)/2,C,(P1+P4)/2,D,S-1);
#if(!Found)
#local Found=Sample_Detection((P1+P2)/2,P2,(P2+P3)/2,C,D,S-1);
#end
#if(!Found)
#local Found=Sample_Detection(C,(P2+P3)/2,P3,(P3+P4)/2,D,S-1);
#end
#if(!Found)
#local Found=Sample_Detection((P1+P4)/2,C,(P3+P4)/2,P4,D,S-1);
#end
#end
#end
#declare K=K+1;
(Found?true:false)
#end
ABX
--
#declare _=function(a,b,x){((a^2)+(b^2))^.5-x}#default {pigment{color rgb 1}}
union{plane{y,-3}plane{-x,-3}finish{reflection 1 ambient 0}}isosurface{ //ABX
function{_(x-2,y,1)|_((x+y)*.7,z,.1)|_((x+y+2)*.7,z,.1)|_(x/2+y*.8+1.5,z,.1)}
contained_by{box{<0,-3,-.1>,<3,0,.1>}}translate z*15finish{ambient 1}}//POV35
Post a reply to this message
|
|